package com.designpattern.behavior.command;

import java.util.ArrayList;

/**
 * @author Administration
 * @date 2021/10/21 - 14:06 - 星期四
 * @project 行为模式中的命令模式 调用者/请求者（Invoker）角色
 * @package com.designpattern.behavior.command
 * @by 晨
 */
public class Waitor {

    private ArrayList<Command> commands;//可以持有很多的命令对象

    public Waitor() {
        commands = new ArrayList();
    }

    public void setCommand(Command cmd){
        commands.add(cmd);
    }

    public void orderUp () throws InterruptedException {
        System.out.println("美女服务员：叮咚，大厨，新订单来了.......");
        for (int i = 0; i < commands.size(); i++) {
            Command command = commands.get(i);
            if (command != null) {
                command.execute();
            }
        }
    }
}
